package xhe.openapi.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import xhe.entities.ApiEntity;
import xhe.inf.service.CommonService;
import xhe.lib.io.Gzip;

@RestController
public class OpenAPIController {

	@Autowired
	private DiscoveryClient iClient;

	@Autowired
	private CommonService iService;

	@RequestMapping(value = "xhe/openapi")
	public void openAPI(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		// 声明请求
		ApiEntity apiEntity = new ApiEntity();

		// 查询
		apiEntity = iService.openAPI(request, response);

		PrintWriter out = response.getWriter();
		out.println("[\"" + Gzip.gZip(apiEntity.getResponse()) + "\"]");
	}
}